<?php

namespace app\admin\model\yunfood;

/**
 * 意见反馈
 */
class Feedback extends \addons\yunfood\model\Feedback
{
    // 自定义初始化
    protected static function init()
    {
        self::beforeWrite(function ($record) {
            $scenario = $record->data['scenario'] ?? null;
            if ($scenario === 'reply') {
                if ($record->reply_content) {
                    $record->status = Feedback::STATUS_HIDDEN;
                    $record->reply_time = time();
                } else {
                    $record->status = Feedback::STATUS_NORMAL;
                    $record->reply_time = 0;
                }
            }

            return true;
        });
    }
}
